home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / tools / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / sh / sh.md < prev    next >
Encoding:
Text File  |  1995-06-15  |  53.4 KB  |  1,813 lines

  1. ;;- Machine description for the Hitachi SH.
  2. ;;  Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  3. ;;  Contributed by Steve Chamberlain (sac@cygnus.com).
  4. ;;  Improved by Jim Wilson (wilson@cygnus.com).
  5.  
  6. ;; This file is part of GNU CC.
  7.  
  8. ;; GNU CC is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 2, or (at your option)
  11. ;; any later version.
  12.  
  13. ;; GNU CC is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;; GNU General Public License for more details.
  17.  
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU CC; see the file COPYING.  If not, write to
  20. ;; the Free Software Foundation, 59 Temple Place - Suite 330,
  21. ;; Boston, MA 02111-1307, USA.
  22.  
  23.  
  24. ;; ??? Should be enhanced to include support for many more GNU superoptimizer
  25. ;; sequences.  Especially the sequences for arithmetic right shifts.
  26.  
  27. ;; ??? Should check all DImode patterns for consistency and usefulness.
  28.  
  29. ;; ??? Should add support for using BSR for short function calls.
  30.  
  31. ;; ??? The MAC.W and MAC.L instructions are not supported.  There is no
  32. ;; way to generate them.
  33.  
  34. ;; ??? The BSR instruction is not supported.  It might be possible to
  35. ;; generate it by keeping track of function sizes (and hence relative
  36. ;; addresses), and then using it only if the target is earlier in the same
  37. ;; file, and is within range.  Better would be assembler/linker relaxing,
  38. ;; but that is much harder.
  39.  
  40. ;; ??? The cmp/str instruction is not supported.  Perhaps it can be used
  41. ;; for a str* inline function.
  42.  
  43. ;; Special constraints for SH machine description:
  44. ;;
  45. ;;    t -- T
  46. ;;    x -- mac
  47. ;;    l -- pr
  48. ;;    z -- r0
  49. ;;
  50. ;; Special formats used for outputting SH instructions:
  51. ;;
  52. ;;   %.  --  print a .s if insn needs delay slot
  53. ;;   %@  --  print rte/rts if is/isn't an interrupt function
  54. ;;   %#  --  output a nop if there is nothing to put in the delay slot
  55. ;;   %O  --  print a constant without the #
  56. ;;   %R  --  print the lsw reg of a double
  57. ;;   %S  --  print the msw reg of a double
  58. ;;   %T  --  print next word of a double REG or MEM
  59. ;;
  60. ;; Special predicates:
  61. ;;
  62. ;;  arith_operand          -- operand is valid source for arithmetic op
  63. ;;  arith_reg_operand      -- operand is valid register for arithmetic op
  64. ;;  general_movdst_operand -- operand is valid move destination
  65. ;;  general_movsrc_operand -- operand is valid move source
  66. ;;  logical_operand        -- operand is valid source for logical op
  67. ;; -------------------------------------------------------------------------
  68. ;; Attributes
  69. ;; -------------------------------------------------------------------------
  70.  
  71. ; Target CPU.
  72.  
  73. (define_attr "cpu" "sh0,sh1,sh2,sh3"
  74.   (const (symbol_ref "sh_cpu_attr")))
  75.  
  76. ;;
  77. ;; cbranch    conditional branch instructions
  78. ;; jump        unconditional jumps
  79. ;; arith    ordinary arithmetic
  80. ;; load        from memory
  81. ;; store    to memory
  82. ;; move        register to register
  83. ;; smpy        word precision integer multiply
  84. ;; dmpy        longword or doublelongword precision integer multiply
  85. ;; return    rts
  86. ;; pload    load of pr reg, which can't be put into delay slot of rts
  87. ;; pstore    store of pr reg, which can't be put into delay slot of jsr
  88. ;; pcload    pc relative load of constant value
  89. ;; rte        return from exception
  90. ;; sfunc    special function call with known used registers
  91. ;; call        function call
  92.  
  93. (define_attr "type"
  94.  "cbranch,jump,arith,other,load,store,move,smpy,dmpy,return,pload,pstore,pcload,rte,sfunc,call"
  95.   (const_string "other"))
  96.  
  97. ; If a conditional branch destination is within -252..258 bytes away
  98. ; from the instruction it can be 2 bytes long.  Something in the
  99. ; range -4090..4100 bytes can be 6 bytes long.  All other conditional
  100. ; branches are 16 bytes long.
  101.  
  102. ; An unconditional jump in the range -4092..4098 can be 2 bytes long.
  103. ; Otherwise, it must be 14 bytes long.
  104.  
  105. ; All other instructions are two bytes long by default.
  106.  
  107. ; All positive offsets have an adjustment added, which is the number of bytes
  108. ; difference between this instruction length and the next larger instruction
  109. ; length.  This is because shorten_branches starts with the largest
  110. ; instruction size and then tries to reduce them.
  111.  
  112. (define_attr "length" ""
  113.   (cond [(eq_attr "type" "cbranch")
  114.      (if_then_else (and (ge (minus (match_dup 0) (pc))
  115.                 (const_int -252))
  116.                 (le (minus (match_dup 0) (pc))
  117.                 (const_int 262)))
  118.                (const_int 2)
  119.                (if_then_else (and (ge (minus (match_dup 0) (pc))
  120.                           (const_int -4090))
  121.                       (le (minus (match_dup 0) (pc))
  122.                           (const_int 4110)))
  123.                      (const_int 6)
  124.                      (const_int 16)))
  125.  
  126.      (eq_attr "type" "jump")
  127.      (if_then_else (and (ge (minus (match_dup 0) (pc))
  128.                 (const_int -4092))
  129.                 (le (minus (match_dup 0) (pc))
  130.                 (const_int 4110)))
  131.                (const_int 2)
  132.                (const_int 14))
  133.      ] (const_int 2)))
  134.  
  135. ;; (define_function_unit {name} {num-units} {n-users} {test}
  136. ;;                       {ready-delay} {issue-delay} [{conflict-list}])
  137.  
  138. ;; ??? These are probably not correct.
  139. (define_function_unit "memory" 1 0 (eq_attr "type" "load,pcload,pload") 2 2)
  140. (define_function_unit "mpy"    1 0 (eq_attr "type" "smpy") 2 2)
  141. (define_function_unit "mpy"    1 0 (eq_attr "type" "dmpy") 3 3)
  142.  
  143. ; Definitions for filling branch delay slots.
  144.  
  145. (define_attr "needs_delay_slot" "yes,no" (const_string "no"))
  146.  
  147. (define_attr "hit_stack" "yes,no" (const_string "no"))
  148.  
  149. (define_attr "interrupt_function" "no,yes"
  150.   (const (symbol_ref "pragma_interrupt")))
  151.  
  152. (define_attr "in_delay_slot" "yes,no"
  153.   (cond [(eq_attr "type" "cbranch") (const_string "no")
  154.      (eq_attr "type" "pcload") (const_string "no")
  155.      (eq_attr "needs_delay_slot" "yes") (const_string "no")
  156.      (eq_attr "length" "2") (const_string "yes")
  157.      ] (const_string "no")))
  158.  
  159. (define_delay
  160.   (eq_attr "needs_delay_slot" "yes")
  161.   [(eq_attr "in_delay_slot" "yes") (nil) (nil)])
  162.  
  163. ;; On the SH and SH2, the rte instruction reads the return pc from the stack,
  164. ;; and thus we can't put a pop instruction in its delay slot.
  165. ;; ??? On the SH3, the rte instruction does not use the stack, so a pop
  166. ;; instruction can go in the delay slot.
  167.  
  168. ;; Since a normal return (rts) implicitly uses the PR register,
  169. ;; we can't allow PR register loads in an rts delay slot.
  170.  
  171. (define_delay
  172.   (eq_attr "type" "return")
  173.   [(and (eq_attr "in_delay_slot" "yes")
  174.     (ior (and (eq_attr "interrupt_function" "no")
  175.           (eq_attr "type" "!pload"))
  176.          (and (eq_attr "interrupt_function" "yes")
  177.           (eq_attr "hit_stack" "no")))) (nil) (nil)])
  178.  
  179. ;; Since a call implicitly uses the PR register, we can't allow
  180. ;; a PR register store in a jsr delay slot.
  181.  
  182. (define_delay
  183.   (ior (eq_attr "type" "call") (eq_attr "type" "sfunc"))
  184.   [(and (eq_attr "in_delay_slot" "yes")
  185.     (eq_attr "type" "!pstore")) (nil) (nil)])
  186.  
  187. ;; Say that we have annulled true branches, since this gives smaller and
  188. ;; faster code when branches are predicted as not taken.
  189.  
  190. ;; ??? Branches which are out-of-range actually have two delay slots,
  191. ;; the first is either always executed or else annulled false, and the
  192. ;; second is always annulled false.  Handling these differently from
  193. ;; in range branches would give better code.
  194.  
  195. (define_delay
  196.   (and (eq_attr "type" "cbranch")
  197.        (eq_attr "cpu" "sh2,sh3"))
  198.   [(eq_attr "in_delay_slot" "yes") (const_int 1) (nil)])
  199.  
  200. ;; -------------------------------------------------------------------------
  201. ;; SImode signed integer comparisons
  202. ;; -------------------------------------------------------------------------
  203.  
  204. (define_insn ""
  205.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  206.     (eq:SI (reg:SI 18)
  207.            (const_int 1)))]
  208.   ""
  209.   "movt    %0")
  210.  
  211. ;; ??? This combiner pattern does not work, because combine does not combine
  212. ;; instructions that set a hard register when SMALL_REGISTER_CLASSES is
  213. ;; defined.  Perhaps use a pseudo-reg for the T bit?
  214.  
  215. (define_insn ""
  216.   [(set (reg:SI 18)
  217.     (eq:SI (and:SI (match_operand:SI 0 "arith_reg_operand" "z,r")
  218.                (match_operand:SI 1 "arith_operand" "L,r"))
  219.            (const_int 0)))]
  220.   ""
  221.   "tst    %1,%0")
  222.  
  223. ;; ??? Perhaps should only accept reg/constant if the register is reg 0.
  224. ;; That would still allow reload to create cmpi instructions, but would
  225. ;; perhaps allow forcing the constant into a register when that is better.
  226. ;; Probably should use r0 for mem/imm compares, but force constant into a
  227. ;; register for pseudo/imm compares.
  228.  
  229. (define_insn "cmpeqsi_t"
  230.   [(set (reg:SI 18) (eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
  231.                (match_operand:SI 1 "arith_operand" "N,rI,r")))]
  232.   ""
  233.   "@
  234.     tst    %0,%0
  235.     cmp/eq    %1,%0
  236.     cmp/eq    %1,%0")
  237.  
  238. (define_insn "cmpgtsi_t"
  239.   [(set (reg:SI 18) (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
  240.                (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
  241.   ""
  242.   "@
  243.     cmp/gt    %1,%0
  244.     cmp/pl    %0")
  245.  
  246. (define_insn "cmpgesi_t"
  247.   [(set (reg:SI 18) (ge:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
  248.                (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
  249.   ""
  250.   "@
  251.     cmp/ge    %1,%0
  252.     cmp/pz    %0")
  253.  
  254. ;; -------------------------------------------------------------------------
  255. ;; SImode unsigned integer comparisons
  256. ;; -------------------------------------------------------------------------
  257.  
  258. (define_insn "cmpgeusi_t"
  259.   [(set (reg:SI 18) (geu:SI (match_operand:SI 0 "arith_reg_operand" "r")
  260.                 (match_operand:SI 1 "arith_reg_operand" "r")))]
  261.   ""
  262.   "cmp/hs    %1,%0")
  263.  
  264. (define_insn "cmpgtusi_t"
  265.   [(set (reg:SI 18) (gtu:SI (match_operand:SI 0 "arith_reg_operand" "r")
  266.                 (match_operand:SI 1 "arith_reg_operand" "r")))]
  267.   ""
  268.   "cmp/hi    %1,%0")
  269.  
  270. ;; We save the compare operands in the cmpxx patterns and use them when
  271. ;; we generate the branch.
  272.  
  273. (define_expand "cmpsi"
  274.   [(set (reg:SI 18) (compare (match_operand:SI 0 "arith_operand" "")
  275.                  (match_operand:SI 1 "arith_operand" "")))]
  276.   ""
  277.   "
  278. {
  279.   sh_compare_op0 = operands[0];
  280.   sh_compare_op1 = operands[1];
  281.   DONE;
  282. }")
  283.  
  284. ;; -------------------------------------------------------------------------
  285. ;; Addition instructions
  286. ;; -------------------------------------------------------------------------
  287.  
  288. ;; ??? This should be a define expand.
  289.  
  290. (define_insn "adddi3"
  291.   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
  292.     (plus:DI (match_operand:DI 1 "arith_reg_operand" "%0")
  293.          (match_operand:DI 2 "arith_reg_operand" "r")))
  294.    (clobber (reg:SI 18))]
  295.   ""
  296.   "clrt\;addc    %R2,%R0\;addc    %S2,%S0"
  297.   [(set_attr "length" "6")])
  298.  
  299. (define_insn "addsi3"
  300.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  301.     (plus:SI (match_operand:SI 1 "arith_operand" "%0")
  302.          (match_operand:SI 2 "arith_operand" "rI")))]
  303.   ""
  304.   "add    %2,%0"
  305.   [(set_attr "type" "arith")])
  306.  
  307. ;; -------------------------------------------------------------------------
  308. ;; Subtraction instructions
  309. ;; -------------------------------------------------------------------------
  310.  
  311. ;; ??? This should be a define expand.
  312.  
  313. (define_insn "subdi3"
  314.   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
  315.     (minus:DI (match_operand:DI 1 "arith_reg_operand" "0")
  316.          (match_operand:DI 2 "arith_reg_operand" "r")))
  317.    (clobber (reg:SI 18))]
  318.   ""
  319.   "clrt\;subc    %R2,%R0\;subc    %S2,%S0"
  320.   [(set_attr "length" "6")])
  321.  
  322. (define_insn "subsi3"
  323.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  324.     (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
  325.           (match_operand:SI 2 "arith_reg_operand" "r")))]
  326.   ""
  327.   "sub    %2,%0"
  328.   [(set_attr "type" "arith")])
  329.  
  330. ;; -------------------------------------------------------------------------
  331. ;; Division instructions
  332. ;; -------------------------------------------------------------------------
  333.  
  334. ;; We take advantage of the library routines which don't clobber as many
  335. ;; registers as a normal function call would.
  336.  
  337. ;; We must use a pseudo-reg forced to reg 0 in the SET_DEST rather than
  338. ;; hard register 0.  If we used hard register 0, then the next instruction
  339. ;; would be a move from hard register 0 to a pseudo-reg.  If the pseudo-reg
  340. ;; gets allocated to a stack slot that needs its address reloaded, then
  341. ;; there is nothing to prevent reload from using r0 to reload the address.
  342. ;; This reload would clobber the value in r0 we are trying to store.
  343. ;; If we let reload allocate r0, then this problem can never happen.
  344.  
  345. (define_insn ""
  346.   [(set (match_operand:SI 1 "register_operand" "=z")
  347.     (udiv:SI (reg:SI 4) (reg:SI 5)))
  348.    (clobber (reg:SI 18))
  349.    (clobber (reg:SI 17))
  350.    (clobber (reg:SI 4))
  351.    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
  352.   ""
  353.   "jsr    @%0%#"
  354.   [(set_attr "type" "sfunc")
  355.    (set_attr "needs_delay_slot" "yes")])
  356.  
  357. (define_expand "udivsi3"
  358.   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
  359.    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
  360.    (set (match_dup 3) (symbol_ref:SI "__udivsi3"))
  361.    (parallel [(set (match_operand:SI 0 "register_operand" "")
  362.            (udiv:SI (reg:SI 4)
  363.                 (reg:SI 5)))
  364.           (clobber (reg:SI 18))
  365.           (clobber (reg:SI 17))
  366.           (clobber (reg:SI 4))
  367.           (use (match_dup 3))])]
  368.   ""
  369.   "operands[3] = gen_reg_rtx(SImode);")
  370.  
  371. (define_insn ""
  372.   [(set (match_operand:SI 1 "register_operand" "=z")
  373.     (div:SI (reg:SI 4) (reg:SI 5)))
  374.    (clobber (reg:SI 18))
  375.    (clobber (reg:SI 17))
  376.    (clobber (reg:SI 1))
  377.    (clobber (reg:SI 2))
  378.    (clobber (reg:SI 3))
  379.    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
  380.   ""
  381.   "jsr    @%0%#"
  382.   [(set_attr "type" "sfunc")
  383.    (set_attr "needs_delay_slot" "yes")])
  384.  
  385. (define_expand "divsi3"
  386.   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
  387.    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
  388.    (set (match_dup 3) (symbol_ref:SI "__sdivsi3"))
  389.    (parallel [(set (match_operand:SI 0 "register_operand" "")
  390.            (div:SI (reg:SI 4)
  391.                (reg:SI 5)))
  392.           (clobber (reg:SI 18))
  393.           (clobber (reg:SI 17))
  394.           (clobber (reg:SI 1))
  395.           (clobber (reg:SI 2))
  396.           (clobber (reg:SI 3))
  397.           (use (match_dup 3))])]
  398.   ""
  399.   "operands[3] = gen_reg_rtx(SImode);")
  400.  
  401. ;; -------------------------------------------------------------------------
  402. ;; Multiplication instructions
  403. ;; -------------------------------------------------------------------------
  404.  
  405. (define_insn ""
  406.   [(set (reg:SI 21)
  407.     (mult:SI (zero_extend:SI (match_operand:HI 1 "arith_reg_operand" "r"))
  408.          (zero_extend:SI (match_operand:HI 2 "arith_reg_operand" "r"))))]
  409.   ""
  410.   "mulu    %2,%1"
  411.   [(set_attr "type" "smpy")])
  412.  
  413. (define_insn ""
  414.   [(set (reg:SI 21)
  415.     (mult:SI (sign_extend:SI
  416.           (match_operand:HI 1 "arith_reg_operand" "r"))
  417.          (sign_extend:SI
  418.           (match_operand:HI 2 "arith_reg_operand" "r"))))]
  419.   ""
  420.   "muls    %2,%1"
  421.   [(set_attr "type" "smpy")])
  422.  
  423. (define_expand "mulhisi3"
  424.   [(set (reg:SI 21)
  425.     (mult:SI (sign_extend:SI
  426.           (match_operand:HI 1 "arith_reg_operand" ""))
  427.          (sign_extend:SI
  428.           (match_operand:HI 2 "arith_reg_operand" ""))))
  429.    (set (match_operand:SI 0 "arith_reg_operand" "")
  430.     (reg:SI 21))]
  431.   ""
  432.   "")
  433.  
  434. (define_expand "umulhisi3"
  435.   [(set (reg:SI 21)
  436.     (mult:SI (zero_extend:SI
  437.           (match_operand:HI 1 "arith_reg_operand" ""))
  438.          (zero_extend:SI
  439.           (match_operand:HI 2 "arith_reg_operand" ""))))
  440.    (set (match_operand:SI 0 "arith_reg_operand" "")
  441.     (reg:SI 21))]
  442.   ""
  443.   "")
  444.  
  445. ;; mulsi3 on the SH2 can be done in one instruction, on the SH1 we generate
  446. ;; a call to a routine which clobbers known registers.
  447.  
  448. (define_insn ""
  449.   [(set (match_operand:SI 1 "register_operand" "=z")
  450.     (mult:SI (reg:SI 4) (reg:SI 5)))
  451.    (clobber (reg:SI 21))
  452.    (clobber (reg:SI 18))
  453.    (clobber (reg:SI 17))
  454.    (clobber (reg:SI 3))
  455.    (clobber (reg:SI 2))
  456.    (clobber (reg:SI 1))
  457.    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
  458.   ""
  459.   "jsr    @%0%#"
  460.   [(set_attr "type" "sfunc")
  461.    (set_attr "needs_delay_slot" "yes")])
  462.  
  463. (define_expand "mulsi3_call"
  464.   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
  465.    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
  466.    (set (match_dup 3) (symbol_ref:SI "__mulsi3"))
  467.    (parallel[(set (match_operand:SI 0 "register_operand" "")
  468.           (mult:SI (reg:SI 4)
  469.                (reg:SI 5)))
  470.          (clobber (reg:SI 21))
  471.          (clobber (reg:SI 18))
  472.          (clobber (reg:SI 17))
  473.          (clobber (reg:SI 3))
  474.          (clobber (reg:SI 2))
  475.          (clobber (reg:SI 1))
  476.          (use (match_dup 3))])]
  477.   ""
  478.   "operands[3] = gen_reg_rtx(SImode);")
  479.  
  480. (define_insn "mul_l"
  481.   [(set (reg:SI 21)
  482.     (mult:SI (match_operand:SI 0 "arith_reg_operand" "r")
  483.          (match_operand:SI 1 "arith_reg_operand" "r")))]
  484.   "TARGET_SH2"
  485.   "mul.l    %1,%0"
  486.   [(set_attr "type" "dmpy")])
  487.  
  488. (define_expand "mulsi3"
  489.   [(set (reg:SI 21)
  490.     (mult:SI  (match_operand:SI 1 "arith_reg_operand" "")
  491.           (match_operand:SI 2 "arith_reg_operand" "")))
  492.    (set (match_operand:SI 0 "arith_reg_operand" "")
  493.     (reg:SI 21))]
  494.   ""
  495.   "
  496. {
  497.   if (!TARGET_SH2)
  498.     {
  499.       FAIL;
  500.       /* ??? Does this give worse or better code?  */
  501.       emit_insn (gen_mulsi3_call (operands[0], operands[1], operands[2]));
  502.       DONE;
  503.     }
  504. }")
  505.  
  506. ;; ??? Why is this disabled?
  507.  
  508. (define_insn ""
  509.   [(set (reg:DI 20)
  510.     (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))
  511.          (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" "r"))))]
  512.   "(TARGET_SH2) && 0"
  513.   "dmuls.l    %2,%1"
  514.   [(set_attr "type" "dmpy")])
  515.  
  516. ;; ??? Why is this disabled?
  517.  
  518. (define_expand "mulsidi3"
  519.   [(set (reg:DI 20)
  520.     (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
  521.          (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))
  522.    (set (match_operand:DI 0 "arith_reg_operand" "")
  523.     (reg:DI 20))]
  524.   "(TARGET_SH2) && 0"
  525.   "")
  526.  
  527. ;; ??? Why is this disabled?
  528.  
  529. (define_insn ""
  530.   [(set (reg:DI 20)
  531.     (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))
  532.          (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" "r"))))]
  533.   "(TARGET_SH2) && 0"
  534.   "dmulu.l    %2,%1"
  535.   [(set_attr "type" "dmpy")])
  536.  
  537. ;; ??? Why is this disabled?
  538.  
  539. (define_expand "umulsidi3"
  540.   [(set (reg:DI 20)
  541.     (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
  542.          (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))
  543.    (set (match_operand:DI 0 "arith_reg_operand" "")
  544.     (reg:DI 20))]
  545.   "(TARGET_SH2) && 0"
  546.   "")
  547.  
  548. ;; -------------------------------------------------------------------------
  549. ;; Logical operations
  550. ;; -------------------------------------------------------------------------
  551.  
  552. (define_insn ""
  553.   [(set (match_operand:SI 0 "arith_reg_operand" "=r,z")
  554.     (and:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
  555.         (match_operand:SI 2 "logical_operand" "r,L")))]
  556.   ""
  557.   "and    %2,%0"
  558.   [(set_attr "type" "arith")])
  559.  
  560. ;; If the constant is 255, then emit a extu.b instruction instead of an
  561. ;; and, since that will give better code.
  562.  
  563. (define_expand "andsi3"
  564.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  565.     (and:SI (match_operand:SI 1 "arith_reg_operand" "")
  566.         (match_operand:SI 2 "logical_operand" "")))]
  567.   ""
  568.   "
  569. {
  570.   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 255)
  571.     {
  572.       emit_insn (gen_zero_extendqisi2 (operands[0],
  573.                        gen_lowpart (QImode, operands[1])));
  574.       DONE;
  575.     }
  576. }")
  577.  
  578. (define_insn "iorsi3"
  579.   [(set (match_operand:SI 0 "arith_reg_operand" "=r,z")
  580.     (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
  581.         (match_operand:SI 2 "logical_operand" "r,L")))]
  582.   ""
  583.   "or    %2,%0")
  584.  
  585. (define_insn "xorsi3"
  586.   [(set (match_operand:SI 0 "arith_reg_operand" "=z,r")
  587.     (xor:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
  588.         (match_operand:SI 2 "logical_operand" "L,r")))]
  589.   ""
  590.   "xor    %2,%0"
  591.   [(set_attr "type" "arith")])
  592.  
  593. ;; -------------------------------------------------------------------------
  594. ;; Shifts and rotates
  595. ;; -------------------------------------------------------------------------
  596.  
  597. (define_insn "rotlsi3_1"
  598.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  599.     (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
  600.            (const_int 1)))
  601.    (set (reg:SI 18)
  602.     (lshiftrt:SI (match_dup 1) (const_int 31)))]
  603.   ""
  604.   "rotl    %0")
  605.  
  606. (define_insn "rotlsi3_31"
  607.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  608.     (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
  609.            (const_int 31)))
  610.    (clobber (reg:SI 18))]
  611.   ""
  612.   "rotr    %0")
  613.  
  614. (define_insn ""
  615.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  616.     (rotate:SI (match_operand:SI 1 "arith_reg_operand" "r")
  617.            (const_int 16)))]
  618.   ""
  619.   "swap.w    %1,%0")
  620.  
  621. (define_expand "rotlsi3"
  622.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  623.     (rotate:SI (match_operand:SI 1 "arith_reg_operand" "")
  624.            (match_operand:SI 2 "immediate_operand" "")))]
  625.   ""
  626.   "
  627. {
  628.   if (GET_CODE (operands[2]) != CONST_INT)
  629.     FAIL;
  630.  
  631.   if (INTVAL (operands[2]) == 1)
  632.     {
  633.       emit_insn (gen_rotlsi3_1 (operands[0], operands[1]));
  634.       DONE;
  635.     }
  636.   else if (INTVAL (operands[2]) == 31)
  637.     {
  638.       emit_insn (gen_rotlsi3_31 (operands[0], operands[1]));
  639.       DONE;
  640.     }
  641.   else if (INTVAL (operands[2]) != 16)
  642.     FAIL;
  643. }")
  644.  
  645. (define_insn ""
  646.   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
  647.     (rotate:HI (match_operand:HI 1 "arith_reg_operand" "r")
  648.            (const_int 8)))]
  649.   ""
  650.   "swap.b    %1,%0")
  651.  
  652. (define_expand "rotlhi3"
  653.   [(set (match_operand:HI 0 "arith_reg_operand" "")
  654.     (rotate:HI (match_operand:HI 1 "arith_reg_operand" "")
  655.            (match_operand:HI 2 "immediate_operand" "")))]
  656.   ""
  657.   "
  658. {
  659.   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 8)
  660.     FAIL;
  661. }")
  662.  
  663. ;;
  664. ;; shift left
  665.  
  666. (define_insn "ashlsi3_d"
  667.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  668.     (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
  669.            (match_operand:SI 2 "arith_reg_operand" "r")))]
  670.   "TARGET_SH3"
  671.   "shld    %2,%0")
  672.  
  673. (define_insn "ashlsi3_k"
  674.   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
  675.     (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0,0")
  676.            (match_operand:SI 2 "const_int_operand" "M,K")))]
  677.   "CONST_OK_FOR_K (INTVAL (operands[2]))"
  678.   "@
  679.     add    %0,%0
  680.     shll%O2    %0")
  681.  
  682. (define_insn "ashlsi3_n"
  683.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  684.     (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
  685.            (match_operand:SI 2 "const_int_operand" "n")))
  686.    (clobber (reg:SI 18))]
  687.   ""
  688.   "#"
  689.   [(set (attr "length")
  690.     (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
  691.            (const_string "2")
  692.            (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
  693.            (const_string "4")
  694.            (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 3))
  695.            (const_string "6")]
  696.           (const_string "8")))
  697.    (set_attr "type" "arith")])
  698.  
  699. (define_split
  700.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  701.     (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
  702.            (match_operand:SI 2 "const_int_operand" "n")))
  703.    (clobber (reg:SI 18))]
  704.   ""
  705.   [(use (reg:SI 0))]
  706.   "
  707. {
  708.   gen_shifty_op (ASHIFT, operands);
  709.   DONE;
  710. }")
  711.  
  712. (define_expand "ashlsi3"
  713.   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
  714.            (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
  715.                   (match_operand:SI 2 "nonmemory_operand" "")))
  716.           (clobber (reg:SI 18))])]
  717.   ""
  718.   "
  719. {
  720.   if (TARGET_SH3 && arith_reg_operand (operands[2], GET_MODE (operands[2])))
  721.     {
  722.       emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
  723.       DONE;
  724.     }
  725.   if (! immediate_operand (operands[2], GET_MODE (operands[2])))
  726.     FAIL;
  727. }")
  728.  
  729. ;
  730. ; arithmetic shift right
  731. ;
  732.  
  733. (define_insn "ashrsi3_k"
  734.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  735.     (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  736.              (match_operand:SI 2 "const_int_operand" "M")))
  737.    (clobber (reg:SI 18))]
  738.   "INTVAL (operands[2]) == 1"
  739.   "shar    %0"
  740.   [(set_attr "type" "arith")])
  741.  
  742. ;; ??? This should be a define expand.
  743.  
  744. (define_insn "ashrsi2_16"
  745.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  746.         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
  747.                      (const_int 16)))]
  748.   ""
  749.   "swap.w    %1,%0\;exts.w    %0,%0"
  750.   [(set_attr "length" "4")])
  751.  
  752. ;; ??? This should be a define expand.
  753.  
  754. (define_insn "ashrsi2_31"
  755.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  756.         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  757.                      (const_int 31)))
  758.    (clobber (reg:SI 18))]
  759.   ""
  760.   "@
  761.    shll    %0\;subc    %0,%0"
  762.   [(set_attr "length" "4")])
  763.  
  764. (define_insn "ashrsi3_d"
  765.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  766.     (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  767.              (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
  768.   "TARGET_SH3"
  769.   "shad    %2,%1")
  770.  
  771. (define_insn "ashrsi3_n"
  772.   [(set (reg:SI 4)
  773.     (ashiftrt:SI (reg:SI 4)
  774.              (match_operand:SI 0 "const_int_operand" "i")))
  775.    (clobber (reg:SI 18))
  776.    (clobber (reg:SI 17))
  777.    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  778.   ""
  779.   "jsr    @%1%#"
  780.   [(set_attr "type" "sfunc")
  781.    (set_attr "needs_delay_slot" "yes")])
  782.  
  783. (define_expand "ashrsi3"
  784.   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
  785.            (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
  786.                 (match_operand:SI 2 "nonmemory_operand" "")))
  787.           (clobber (reg:SI 18))])]
  788.   ""
  789.   "if (expand_ashiftrt (operands)) DONE; else FAIL;")
  790.  
  791. ;; logical shift right
  792.  
  793. (define_insn "lshrsi3_d"
  794.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  795.     (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  796.              (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
  797.   "TARGET_SH3"
  798.   "shld    %2,%0")
  799.  
  800. ;;  Only the single bit shift clobbers the T bit.
  801.  
  802. (define_insn "lshrsi3_m"
  803.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  804.     (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  805.              (match_operand:SI 2 "const_int_operand" "M")))
  806.    (clobber (reg:SI 18))]
  807.   "CONST_OK_FOR_M (INTVAL (operands[2]))"
  808.   "shlr    %0")
  809.  
  810. (define_insn "lshrsi3_k"
  811.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  812.     (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  813.              (match_operand:SI 2 "const_int_operand" "K")))]
  814.   "CONST_OK_FOR_K (INTVAL (operands[2]))
  815.    && ! CONST_OK_FOR_M (INTVAL (operands[2]))"
  816.   "shlr%O2    %0")
  817.  
  818. (define_insn "lshrsi3_n"
  819.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  820.     (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
  821.              (match_operand:SI 2 "const_int_operand" "n")))
  822.    (clobber (reg:SI 18))]
  823.   ""
  824.   "#"
  825.   [(set (attr "length")
  826.     (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
  827.            (const_string "2")
  828.            (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
  829.            (const_string "4")
  830.            (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 3))
  831.            (const_string "6")]
  832.           (const_string "8")))
  833.    (set_attr "type" "arith")])
  834.  
  835. (define_split
  836.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  837.     (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
  838.              (match_operand:SI 2 "const_int_operand" "n")))
  839.    (clobber (reg:SI 18))]
  840.   ""
  841.   [(use (reg:SI 0))]
  842.   "
  843. {
  844.   gen_shifty_op (LSHIFTRT, operands);
  845.   DONE;
  846. }")
  847.  
  848. (define_expand "lshrsi3"
  849.   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
  850.            (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
  851.                 (match_operand:SI 2 "nonmemory_operand" "")))
  852.           (clobber (reg:SI 18))])]
  853.   ""
  854.   "
  855. {
  856.   if (TARGET_SH3 && arith_reg_operand (operands[2], GET_MODE (operands[2])))
  857.     {
  858.       rtx count = copy_to_mode_reg (SImode, operands[2]);
  859.       emit_insn (gen_negsi2 (count, count));
  860.       emit_insn (gen_ashlsi3_d (operands[0], operands[1], count));
  861.       DONE;
  862.     }
  863.   if (! immediate_operand (operands[2], GET_MODE (operands[2])))
  864.     FAIL;
  865. }")
  866.  
  867. ;; ??? This should be a define expand.
  868.  
  869. (define_insn "ashldi3_k"
  870.   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
  871.     (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
  872.            (const_int 1)))
  873.    (clobber (reg:SI 18))]
  874.   ""
  875.   "shll    %R0\;rotcl    %S0"
  876.   [(set_attr "length" "4")])
  877.  
  878. (define_expand "ashldi3"
  879.   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
  880.            (ashift:DI (match_operand:DI 1 "arith_reg_operand" "")
  881.                   (match_operand:DI 2 "immediate_operand" "")))
  882.           (clobber (reg:SI 18))])]
  883.   ""
  884.   "{ if (GET_CODE (operands[2]) != CONST_INT
  885.      || INTVAL (operands[2]) != 1) FAIL;} ")
  886.  
  887. ;; ??? This should be a define expand.
  888.  
  889. (define_insn "lshrdi3_k"
  890.   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
  891.     (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
  892.              (const_int 1)))
  893.    (clobber (reg:SI 18))]
  894.   ""
  895.   "shlr    %S0\;rotcr    %R0"
  896.   [(set_attr "length" "4")])
  897.  
  898. (define_expand "lshrdi3"
  899.   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
  900.            (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
  901.                    (match_operand:DI 2 "immediate_operand" "")))
  902.          (clobber (reg:SI 18))])]
  903.   ""
  904.   "{ if (GET_CODE (operands[2]) != CONST_INT
  905.      || INTVAL (operands[2]) != 1) FAIL;} ")
  906.  
  907. ;; ??? This should be a define expand.
  908.  
  909. (define_insn "ashrdi3_k"
  910.   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
  911.     (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
  912.              (const_int 1)))
  913.    (clobber (reg:SI 18))]
  914.   ""
  915.   "shar    %S0\;rotcr    %R0"
  916.   [(set_attr "length" "4")])
  917.  
  918. (define_expand "ashrdi3"
  919.   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
  920.            (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
  921.                 (match_operand:DI 2 "immediate_operand" "")))
  922.           (clobber (reg:SI 18))])]
  923.   ""
  924.   "{ if (GET_CODE (operands[2]) != CONST_INT
  925.      || INTVAL (operands[2]) != 1) FAIL; } ")
  926.  
  927. ;; -------------------------------------------------------------------------
  928. ;; Unary arithmetic
  929. ;; -------------------------------------------------------------------------
  930.  
  931. (define_insn "negc"
  932.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  933.     (neg:SI (plus:SI (reg:SI 18)
  934.              (match_operand:SI 1 "arith_reg_operand" "r"))))
  935.    (set (reg:SI 18)
  936.     (ne:SI (ior:SI (reg:SI 18) (match_dup 1))
  937.            (const_int 0)))]
  938.   ""
  939.   "negc    %1,%0"
  940.   [(set_attr "type" "arith")])
  941.  
  942. (define_expand "negdi2"
  943.   [(set (match_operand:DI 0 "arith_reg_operand" "")
  944.     (neg:DI (match_operand:DI 1 "arith_reg_operand" "")))
  945.    (clobber (reg:SI 18))]
  946.   ""
  947.   "
  948. {
  949.   rtx low_src = operand_subword (operands[1], 1, 0, DImode);
  950.   rtx high_src = operand_subword (operands[1], 0, 0, DImode);
  951.  
  952.   rtx low_dst = operand_subword (operands[0], 1, 1, DImode);
  953.   rtx high_dst = operand_subword (operands[0], 0, 1, DImode);
  954.  
  955.   emit_insn (gen_clrt ());
  956.   emit_insn (gen_negc (low_dst, low_src));
  957.   emit_insn (gen_negc (high_dst, high_src));
  958.   DONE;
  959. }")
  960.  
  961. (define_insn "negsi2"
  962.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  963.     (neg:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
  964.   ""
  965.   "neg    %1,%0"
  966.   [(set_attr "type" "arith")])
  967.  
  968. (define_insn "one_cmplsi2"
  969.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  970.     (not:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
  971.   ""
  972.   "not    %1,%0"
  973.   [(set_attr "type" "arith")])
  974.  
  975. ;; -------------------------------------------------------------------------
  976. ;; Zero extension instructions
  977. ;; -------------------------------------------------------------------------
  978.  
  979. (define_insn "zero_extendhisi2"
  980.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  981.     (zero_extend:SI (match_operand:HI 1 "arith_reg_operand" "r")))]
  982.   ""
  983.   "extu.w    %1,%0"
  984.   [(set_attr "type" "arith")])
  985.  
  986. (define_insn "zero_extendqisi2"
  987.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  988.     (zero_extend:SI (match_operand:QI 1 "arith_reg_operand" "r")))]
  989.   ""
  990.   "extu.b    %1,%0"
  991.   [(set_attr "type" "arith")])
  992.  
  993. (define_insn "zero_extendqihi2"
  994.   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
  995.     (zero_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
  996.   ""
  997.   "extu.b    %1,%0"
  998.   [(set_attr "type" "arith")])
  999.  
  1000. ;; -------------------------------------------------------------------------
  1001. ;; Sign extension instructions
  1002. ;; -------------------------------------------------------------------------
  1003.  
  1004. ;; ??? This should be a define expand.
  1005. ;; ??? Or perhaps it should be dropped?
  1006.  
  1007. (define_insn "extendsidi2"
  1008.   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
  1009.     (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
  1010.    (clobber (reg:SI 18))]
  1011.   ""
  1012.   "mov    %1,%S0\;mov    %1,%R0\;shll    %S0\;subc    %S0,%S0"
  1013.   [(set_attr "length" "8")])
  1014.  
  1015. (define_insn "extendhisi2"
  1016.   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
  1017.     (sign_extend:SI (match_operand:HI 1 "general_movsrc_operand" "r,m")))]
  1018.   ""
  1019.   "@
  1020.     exts.w    %1,%0
  1021.        mov.w    %1,%0"
  1022.   [(set_attr "type" "arith,load")])
  1023.  
  1024. (define_insn "extendqisi2"
  1025.   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
  1026.     (sign_extend:SI (match_operand:QI 1 "general_movsrc_operand" "r,m")))]
  1027.   ""
  1028.   "@
  1029.     exts.b    %1,%0
  1030.     mov.b    %1,%0"
  1031.   [(set_attr "type" "arith,load")])
  1032.  
  1033. (define_insn "extendqihi2"
  1034.   [(set (match_operand:HI 0 "arith_reg_operand" "=r,r")
  1035.     (sign_extend:HI (match_operand:QI 1 "general_movsrc_operand" "r,m")))]
  1036.   ""
  1037.   "@
  1038.     exts.b    %1,%0
  1039.     mov.b    %1,%0"
  1040.   [(set_attr "type" "arith,load")])
  1041.  
  1042. ;; -------------------------------------------------------------------------
  1043. ;; Move instructions
  1044. ;; -------------------------------------------------------------------------
  1045.  
  1046. ;; define push and pop so it is easy for sh.c
  1047.  
  1048. (define_insn "push"
  1049.   [(set (mem:SI (pre_dec:SI (reg:SI 15)))
  1050.     (match_operand:SI 0 "register_operand" "r,l,x"))]
  1051.   ""
  1052.   "@
  1053.     mov.l    %0,@-r15
  1054.     sts.l    %0,@-r15
  1055.     sts.l    %0,@-r15"
  1056.   [(set_attr "type" "store,pstore,store")
  1057.    (set_attr "hit_stack" "yes")])
  1058.  
  1059. (define_insn "pop"
  1060.   [(set (match_operand:SI 0 "register_operand" "=r,l,x")
  1061.     (mem:SI (post_inc:SI (reg:SI 15))))]
  1062.   ""
  1063.   "@
  1064.     mov.l    @r15+,%0
  1065.     lds.l    @r15+,%0
  1066.     lds.l    @r15+,%0"
  1067.   [(set_attr "type" "load,pload,load")
  1068.    (set_attr "hit_stack" "yes")])
  1069.  
  1070. ;; These two patterns can happen as the result of optimization, when
  1071. ;; comparisons get simplified to a move of zero or 1 into the T reg.
  1072. ;; They don't disappear completely, because the T reg is a fixed hard reg.
  1073.  
  1074. (define_insn "clrt"
  1075.   [(set (reg:SI 18) (const_int 0))]
  1076.   ""
  1077.   "clrt")
  1078.  
  1079. (define_insn "sett"
  1080.   [(set (reg:SI 18) (const_int 1))]
  1081.   ""
  1082.   "sett")
  1083.  
  1084. ;; t/z is first, so that it will be preferred over r/r when reloading a move
  1085. ;; of a pseudo-reg into the T reg
  1086. (define_insn "movsi_i"
  1087.   [(set (match_operand:SI 0 "general_movdst_operand" "=t,r,r,r,r,r,m,<,xl,xl,r")
  1088.     (match_operand:SI 1 "general_movsrc_operand" "z,Q,rI,m,xl,t,r,xl,r,>,i"))]
  1089.   "register_operand (operands[0], SImode)
  1090.    || register_operand (operands[1], SImode)"
  1091.   "@
  1092.     tst    %1,%1\;rotcl    %1\;xor    #1,%1\;rotcr    %1
  1093.     mov.l    %1,%0
  1094.     mov    %1,%0
  1095.     mov.l    %1,%0
  1096.     sts    %1,%0
  1097.     movt    %0
  1098.     mov.l    %1,%0
  1099.     sts.l    %1,%0
  1100.     lds    %1,%0
  1101.     lds.l    %1,%0
  1102.     fake    %1,%0"
  1103.   [(set_attr "type" "move,pcload,move,load,move,store,store,move,load,move,move")
  1104.    (set_attr "length" "8,*,*,*,*,*,*,*,*,*,*")])
  1105.  
  1106. (define_expand "movsi"
  1107.   [(set (match_operand:SI 0 "general_movdst_operand" "")
  1108.     (match_operand:SI 1 "general_movsrc_operand" ""))]
  1109.   ""
  1110.   "{ if (prepare_move_operands (operands, SImode)) DONE; }")
  1111.  
  1112. (define_insn "movqi_i"
  1113.   [(set (match_operand:QI 0 "general_movdst_operand" "=r,r,m,r,r,l")
  1114.     (match_operand:QI 1 "general_movsrc_operand"  "ri,m,r,t,l,r"))]
  1115.   "arith_reg_operand (operands[0], QImode)
  1116.    || arith_reg_operand (operands[1], QImode)"
  1117.   "@
  1118.     mov    %1,%0
  1119.     mov.b    %1,%0
  1120.     mov.b    %1,%0
  1121.     movt    %0
  1122.     sts    %1,%0
  1123.     lds    %1,%0"
  1124.  [(set_attr "type" "move,load,store,move,move,move")])
  1125.  
  1126. (define_expand "movqi"
  1127.   [(set (match_operand:QI 0 "general_operand" "")
  1128.     (match_operand:QI 1 "general_operand"  ""))]
  1129.   ""
  1130.   "{ if (prepare_move_operands (operands, QImode)) DONE; }")
  1131.  
  1132. (define_insn "movhi_i"
  1133.   [(set (match_operand:HI 0 "general_movdst_operand" "=r,r,r,r,m,r,l,r")
  1134.     (match_operand:HI 1 "general_movsrc_operand" "Q,rI,m,t,r,l,r,i"))]
  1135.   "arith_reg_operand (operands[0], HImode)
  1136.    || arith_reg_operand (operands[1], HImode)"
  1137.   "@
  1138.     mov.w    %1,%0
  1139.     mov    %1,%0
  1140.     mov.w    %1,%0
  1141.     movt    %0
  1142.     mov.w    %1,%0
  1143.     sts    %1,%0
  1144.     lds    %1,%0
  1145.     fake    %1,%0"
  1146.   [(set_attr "type" "pcload,move,load,move,store,move,move,move")])
  1147.  
  1148. (define_expand "movhi"
  1149.   [(set (match_operand:HI 0 "general_movdst_operand" "")
  1150.     (match_operand:HI 1 "general_movsrc_operand"  ""))]
  1151.   ""
  1152.   "{ if (prepare_move_operands (operands, HImode)) DONE; }")
  1153.  
  1154. ;; ??? This should be a define expand.
  1155.  
  1156. (define_insn ""
  1157.   [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,m,r")
  1158.     (match_operand:DI 1 "general_movsrc_operand" "Q,r,m,r,i"))]
  1159.   "arith_reg_operand (operands[0], DImode)
  1160.    || arith_reg_operand (operands[1], DImode)"
  1161.   "* return output_movedouble (insn, operands, DImode);"
  1162.   [(set_attr "length" "4")
  1163.    (set_attr "type" "pcload,move,load,store,move")])
  1164.  
  1165. ;; If the output is a register and the input is memory, we have to be careful
  1166. ;; and see which word needs to be loaded first.
  1167.  
  1168. ;; ??? Why are Q constraint addresses rejected here but not in the DFmode
  1169. ;; split pattern?
  1170.  
  1171. (define_split
  1172.   [(set (match_operand:DI 0 "general_movdst_operand" "")
  1173.     (match_operand:DI 1 "general_movsrc_operand" ""))]
  1174.  "! (GET_CODE (operands[0]) == REG
  1175.      && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
  1176.    && ! (GET_CODE (operands[1]) == REG
  1177.          && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
  1178.    && ! (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
  1179.      && ! reload_completed
  1180.      && reg_overlap_mentioned_p (operands[0], operands[1]))
  1181.    && ! (GET_CODE (operands[0]) == MEM
  1182.      && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  1183.    && ! (GET_CODE (operands[1]) == MEM
  1184.      && GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  1185.    && ! EXTRA_CONSTRAINT_Q (operands[1])"
  1186.   [(set (match_dup 2) (match_dup 3))
  1187.    (set (match_dup 4) (match_dup 5))]
  1188.   "
  1189. { if (GET_CODE (operands[0]) != REG
  1190.       || ! refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
  1191.                   operands[1], 0))
  1192.     {
  1193.       operands[2] = operand_subword (operands[0], 0, 0, DImode);
  1194.       operands[3] = operand_subword (operands[1], 0, 0, DImode);
  1195.       operands[4] = operand_subword (operands[0], 1, 0, DImode);
  1196.       operands[5] = operand_subword (operands[1], 1, 0, DImode);
  1197.     }
  1198.   else
  1199.     {
  1200.       operands[2] = operand_subword (operands[0], 1, 0, DImode);
  1201.       operands[3] = operand_subword (operands[1], 1, 0, DImode);
  1202.       operands[4] = operand_subword (operands[0], 0, 0, DImode);
  1203.       operands[5] = operand_subword (operands[1], 0, 0, DImode);
  1204.     }
  1205.  
  1206.   if (operands[2] == 0 || operands[3] == 0
  1207.       || operands[4] == 0 || operands[5] == 0)
  1208.     FAIL;
  1209. }")
  1210.  
  1211. (define_expand "movdi"
  1212.   [(set (match_operand:DI 0 "general_movdst_operand" "")
  1213.     (match_operand:DI 1 "general_movsrc_operand" ""))]
  1214.   ""
  1215.   "{ if ( prepare_move_operands (operands, DImode)) DONE; }")
  1216.  
  1217. ;; ??? This should be a define expand.
  1218.  
  1219. (define_insn "movdf_k"
  1220.   [(set (match_operand:DF 0 "general_movdst_operand" "=r,r,m")
  1221.     (match_operand:DF 1 "general_movsrc_operand" "r,m,r"))]
  1222.   "arith_reg_operand (operands[0], DFmode)
  1223.    || arith_reg_operand (operands[1], DFmode)"
  1224.   "* return output_movedouble (insn, operands, DFmode);"
  1225.   [(set_attr "length" "4")
  1226.    (set_attr "type" "move,load,store")])
  1227.  
  1228. ;; If the output is a register and the input is memory, we have to be careful
  1229. ;; and see which word needs to be loaded first.
  1230.  
  1231. (define_split
  1232.   [(set (match_operand:DF 0 "general_movdst_operand" "")
  1233.     (match_operand:DF 1 "general_movsrc_operand" ""))]
  1234.   "! (GET_CODE (operands[0]) == REG
  1235.      && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
  1236.    && ! (GET_CODE (operands[1]) == REG
  1237.          && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
  1238.    && ! (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
  1239.      && ! reload_completed
  1240.      && reg_overlap_mentioned_p (operands[0], operands[1]))
  1241.    && ! (GET_CODE (operands[0]) == MEM
  1242.      && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  1243.    && ! (GET_CODE (operands[1]) == MEM
  1244.      && GET_CODE (XEXP (operands[1], 0)) == POST_INC)"
  1245.   [(set (match_dup 2) (match_dup 3))
  1246.    (set (match_dup 4) (match_dup 5))]
  1247.   "
  1248. { if (GET_CODE (operands[0]) != REG
  1249.       || ! refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
  1250.                   operands[1], 0))
  1251.     {
  1252.       operands[2] = operand_subword (operands[0], 0, 0, DFmode);
  1253.       operands[3] = operand_subword (operands[1], 0, 0, DFmode);
  1254.       operands[4] = operand_subword (operands[0], 1, 0, DFmode);
  1255.       operands[5] = operand_subword (operands[1], 1, 0, DFmode);
  1256.     }
  1257.   else
  1258.     {
  1259.       operands[2] = operand_subword (operands[0], 1, 0, DFmode);
  1260.       operands[3] = operand_subword (operands[1], 1, 0, DFmode);
  1261.       operands[4] = operand_subword (operands[0], 0, 0, DFmode);
  1262.       operands[5] = operand_subword (operands[1], 0, 0, DFmode);
  1263.     }
  1264.  
  1265.   if (operands[2] == 0 || operands[3] == 0
  1266.       || operands[4] == 0 || operands[5] == 0)
  1267.     FAIL;
  1268. }")
  1269.  
  1270. (define_expand "movdf"
  1271.   [(set (match_operand:DF 0 "general_movdst_operand" "")
  1272.     (match_operand:DF 1 "general_movsrc_operand" ""))]
  1273.   ""
  1274.   "{ if (prepare_move_operands (operands, DFmode)) DONE; }")
  1275.  
  1276. (define_insn "movsf_i"
  1277.   [(set (match_operand:SF 0 "general_movdst_operand" "=r,r,r,m,l,r")
  1278.     (match_operand:SF 1 "general_movsrc_operand"  "r,I,m,r,r,l"))]
  1279.   "arith_reg_operand (operands[0], SFmode)
  1280.    || arith_reg_operand (operands[1], SFmode)"
  1281.   "@
  1282.     mov    %1,%0
  1283.     mov    %1,%0
  1284.     mov.l    %1,%0
  1285.     mov.l    %1,%0
  1286.     lds    %1,%0
  1287.     sts    %1,%0"
  1288.   [(set_attr "type" "move,move,load,store,move,move")])
  1289.  
  1290. (define_expand "movsf"
  1291.   [(set (match_operand:SF 0 "general_movdst_operand" "")
  1292.     (match_operand:SF 1 "general_movsrc_operand" ""))]
  1293.   ""
  1294.   "{ if (prepare_move_operands (operands, SFmode)) DONE; }")
  1295.  
  1296. ;; ------------------------------------------------------------------------
  1297. ;; Define the real conditional branch instructions.
  1298. ;; ------------------------------------------------------------------------
  1299.  
  1300. (define_insn "branch_true"
  1301.   [(set (pc) (if_then_else (eq (reg:SI 18) (const_int 1))
  1302.                (label_ref (match_operand 0 "" ""))
  1303.                (pc)))]
  1304.   ""
  1305.   "* return output_branch (1, insn, operands);"
  1306.   [(set_attr "type" "cbranch")])
  1307.  
  1308. (define_insn "branch_false"
  1309.   [(set (pc) (if_then_else (ne (reg:SI 18) (const_int 1))
  1310.                (label_ref (match_operand 0 "" ""))
  1311.                (pc)))]
  1312.   ""
  1313.   "* return output_branch (0, insn, operands);"
  1314.   [(set_attr "type" "cbranch")])
  1315.  
  1316. (define_insn "inverse_branch_true"
  1317.   [(set (pc) (if_then_else (eq (reg:SI 18) (const_int 1))
  1318.                (pc)
  1319.                (label_ref (match_operand 0 "" ""))))]
  1320.   ""
  1321.   "* return output_branch (0, insn, operands);"
  1322.   [(set_attr "type" "cbranch")])
  1323.  
  1324. (define_insn "inverse_branch_false"
  1325.   [(set (pc) (if_then_else (ne (reg:SI 18) (const_int 1))
  1326.                   (pc)
  1327.                (label_ref (match_operand 0 "" ""))))]
  1328.   ""
  1329.   "* return output_branch (1, insn, operands);"
  1330.   [(set_attr "type" "cbranch")])
  1331.  
  1332. ;; Conditional branch insns
  1333.  
  1334. (define_expand "beq"
  1335.   [(set (reg:SI 18) (eq:SI (match_dup 1) (match_dup 2)))
  1336.    (set (pc)
  1337.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1338.               (label_ref (match_operand 0 "" ""))
  1339.               (pc)))]
  1340.   ""
  1341.   "from_compare (operands, EQ);")
  1342.  
  1343. ; There is no bne compare, so we reverse the branch arms.
  1344.  
  1345. (define_expand "bne"
  1346.   [(set (reg:SI 18) (eq:SI (match_dup 1) (match_dup 2)))
  1347.    (set (pc)
  1348.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1349.               (pc)
  1350.               (label_ref (match_operand 0 "" ""))))]
  1351.   ""
  1352.   "from_compare (operands, NE);")
  1353.  
  1354. (define_expand "bgt"
  1355.   [(set (reg:SI 18) (gt:SI (match_dup 1) (match_dup 2)))
  1356.    (set (pc)
  1357.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1358.               (label_ref (match_operand 0 "" ""))
  1359.               (pc)))]
  1360.   ""
  1361.   "from_compare (operands, GT);")
  1362.  
  1363. (define_expand "blt"
  1364.   [(set (reg:SI 18) (ge:SI (match_dup 1) (match_dup 2)))
  1365.    (set (pc)
  1366.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1367.               (pc)
  1368.               (label_ref (match_operand 0 "" ""))))]
  1369.   ""
  1370.   "from_compare (operands, LT);")
  1371.  
  1372. (define_expand "ble"
  1373.   [(set (reg:SI 18) (gt:SI (match_dup 1) (match_dup 2)))
  1374.    (set (pc)
  1375.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1376.               (pc)
  1377.               (label_ref (match_operand 0 "" ""))))]
  1378.   ""
  1379.   "from_compare (operands, LE);")
  1380.  
  1381. (define_expand "bge"
  1382.   [(set (reg:SI 18) (ge:SI (match_dup 1) (match_dup 2)))
  1383.    (set (pc)
  1384.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1385.               (label_ref (match_operand 0 "" ""))
  1386.               (pc)))]
  1387.   ""
  1388.   "from_compare (operands, GE);")
  1389.  
  1390. (define_expand "bgtu"
  1391.   [(set (reg:SI 18) (gtu:SI (match_dup 1) (match_dup 2)))
  1392.    (set (pc)
  1393.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1394.               (label_ref (match_operand 0 "" ""))
  1395.               (pc)))]
  1396.   ""
  1397.   "from_compare (operands, GTU); ")
  1398.  
  1399. (define_expand "bltu"
  1400.   [(set (reg:SI 18) (geu:SI (match_dup 1) (match_dup 2)))
  1401.    (set (pc)
  1402.           (if_then_else (eq (reg:SI 18) (const_int 1))
  1403.                 (pc)
  1404.                 (label_ref (match_operand 0 "" ""))))]
  1405.   ""
  1406.   "from_compare (operands, LTU);")
  1407.  
  1408. (define_expand "bgeu"
  1409.   [(set (reg:SI 18) (geu:SI (match_dup 1) (match_dup 2)))
  1410.    (set (pc)
  1411.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1412.               (label_ref (match_operand 0 "" ""))
  1413.               (pc)))]
  1414.   ""
  1415.   "from_compare (operands, GEU);")
  1416.  
  1417. (define_expand "bleu"
  1418.   [(set (reg:SI 18) (gtu:SI (match_dup 1) (match_dup 2)))
  1419.    (set (pc)
  1420.     (if_then_else (eq (reg:SI 18) (const_int 1))
  1421.               (pc)
  1422.               (label_ref (match_operand 0 "" ""))))]
  1423.   ""
  1424.   "from_compare (operands, LEU);")
  1425.  
  1426. ;; ------------------------------------------------------------------------
  1427. ;; Jump and linkage insns
  1428. ;; ------------------------------------------------------------------------
  1429.  
  1430. (define_insn "jump"
  1431.   [(set (pc)
  1432.     (label_ref (match_operand 0 "" "")))]
  1433.   ""
  1434.   "*
  1435. {
  1436.   /* The length is 16 if the delay slot is unfilled.  */
  1437.   if (get_attr_length(insn) >= 14)
  1438.     return output_far_jump(insn, operands[0]);
  1439.   else
  1440.     return   \"bra    %l0%#\";
  1441. }"
  1442.   [(set_attr "type" "jump")
  1443.    (set_attr "needs_delay_slot" "yes")])
  1444.  
  1445. (define_insn "calli"
  1446.   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
  1447.      (match_operand 1 "" ""))
  1448.    (clobber (reg:SI 17))]
  1449.   ""
  1450.   "jsr    @%0%#"
  1451.   [(set_attr "type" "call")
  1452.    (set_attr "needs_delay_slot" "yes")])
  1453.  
  1454. (define_insn "call_valuei"
  1455.   [(set (match_operand 0 "" "=rf")
  1456.     (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
  1457.           (match_operand 2 "" "")))
  1458.    (clobber (reg:SI 17))]
  1459.   ""
  1460.   "jsr    @%1%#"
  1461.   [(set_attr "type" "call")
  1462.    (set_attr "needs_delay_slot" "yes")])
  1463.  
  1464. (define_expand "call"
  1465.   [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
  1466.                 (match_operand 1 "" ""))
  1467.           (clobber (reg:SI 17))])]
  1468.   ""
  1469.   "operands[0] = force_reg (SImode, XEXP (operands[0], 0));")
  1470.  
  1471. (define_expand "call_value"
  1472.   [(parallel [(set (match_operand 0 "arith_reg_operand" "")
  1473.            (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
  1474.                  (match_operand 2 "" "")))
  1475.           (clobber (reg:SI 17))])]
  1476.   ""
  1477.   "operands[1] = force_reg (SImode, XEXP (operands[1], 0));")
  1478.  
  1479. (define_insn "indirect_jump"
  1480.   [(set (pc)
  1481.     (match_operand:SI 0 "arith_reg_operand" "r"))]
  1482.   ""
  1483.   "jmp    @%0%#"
  1484.   [(set_attr "needs_delay_slot" "yes")])
  1485.  
  1486. ;; ------------------------------------------------------------------------
  1487. ;; Misc insns
  1488. ;; ------------------------------------------------------------------------
  1489.  
  1490. ;; ??? This combiner pattern does not work, because combine does not combine
  1491. ;; instructions that set a hard register when SMALL_REGISTER_CLASSES is
  1492. ;; defined.  Perhaps use a pseudo-reg for the T bit?
  1493.  
  1494. (define_insn "dect"
  1495.   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  1496.            (plus:SI (match_dup 0)
  1497.                 (const_int -1)))
  1498.           (set (reg:SI 18)
  1499.            (eq:SI (plus:SI (match_dup 0) (const_int -1))
  1500.               (const_int 0)))])]
  1501.   "TARGET_SH2"
  1502.   "dt    %0")
  1503.  
  1504. (define_insn "nop"
  1505.   [(const_int 0)]
  1506.   ""
  1507.   "nop")
  1508.  
  1509. ;; Load address of a label. This is only generated by the casesi expand.
  1510. ;; This must use unspec, because this only works immediately before a casesi.
  1511.  
  1512. (define_insn "mova"
  1513.   [(set (reg:SI 0)
  1514.     (unspec [(label_ref (match_operand 0 "" ""))] 1))]
  1515.   ""
  1516.   "mova    %O0,r0"
  1517.   [(set_attr "in_delay_slot" "no")])
  1518.  
  1519. ;; case instruction for switch statements.
  1520.  
  1521. ;; Operand 0 is index
  1522. ;; operand 1 is the minimum bound
  1523. ;; operand 2 is the maximum bound - minimum bound + 1
  1524. ;; operand 3 is CODE_LABEL for the table;
  1525. ;; operand 4 is the CODE_LABEL to go to if index out of range.
  1526.  
  1527. ;; ??? There should be a barrier after the jump at the end.
  1528.  
  1529. (define_expand "casesi"
  1530.   [(set (match_dup 5) (match_operand:SI 0 "arith_reg_operand" ""))
  1531.    (set (match_dup 5) (minus:SI (match_dup 5)
  1532.                 (match_operand:SI 1 "arith_operand" "")))
  1533.    (set (reg:SI 18)
  1534.     (gtu:SI (match_dup 5)
  1535.         (match_operand:SI 2 "arith_reg_operand" "")))
  1536.    (set (pc)
  1537.     (if_then_else (eq (reg:SI 18)
  1538.               (const_int 1))
  1539.               (label_ref (match_operand 4 "" ""))
  1540.               (pc)))
  1541.    (set (match_dup 6) (match_dup 5))
  1542.    (set (match_dup 6) (ashift:SI (match_dup 6) (match_dup 7)))
  1543.    (set (reg:SI 0) (unspec [(label_ref (match_operand 3 "" ""))] 1))
  1544.    (parallel [(set (reg:SI 0) (plus:SI (reg:SI 0)
  1545.                        (mem:HI (plus:SI (reg:SI 0)
  1546.                             (match_dup 6)))))
  1547.           (set (match_dup 6) (mem:HI (plus:SI (reg:SI 0) (match_dup 6))))])
  1548.    (set (pc) (reg:SI 0))]
  1549.   ""
  1550.   "
  1551. {
  1552.   operands[1] = copy_to_mode_reg (SImode, operands[1]);
  1553.   operands[2] = copy_to_mode_reg (SImode, operands[2]);
  1554.   operands[5] = gen_reg_rtx (SImode);
  1555.   operands[6] = gen_reg_rtx (SImode);
  1556.   operands[7] = GEN_INT (TARGET_BIGTABLE  ? 2 : 1);
  1557. }")
  1558.  
  1559. (define_insn "casesi_worker"
  1560.   [(set (reg:SI 0)
  1561.     (plus:SI (reg:SI 0)
  1562.          (mem:HI (plus:SI (reg:SI 0)
  1563.                   (match_operand:SI 0 "arith_reg_operand" "=r")))))
  1564.    (set (match_dup 0) (mem:HI (plus:SI (reg:SI 0)
  1565.                        (match_dup 0))))]
  1566.   ""
  1567.   "*
  1568. {
  1569.   if (TARGET_BIGTABLE)
  1570.     return \"mov.l    @(r0,%0),%0\;add    %0,r0\";
  1571.   else
  1572.     return \"mov.w    @(r0,%0),%0\;add    %0,r0\";
  1573. }"
  1574.   [(set_attr "length" "4")])
  1575.  
  1576. (define_insn "return"
  1577.   [(return)]
  1578.   "reload_completed"
  1579.   "%@    %#"
  1580.   [(set_attr "type" "return")
  1581.    (set_attr "needs_delay_slot" "yes")])
  1582.  
  1583. (define_expand "prologue"
  1584.   [(const_int 0)]
  1585.   ""
  1586.   "sh_expand_prologue (); DONE;")
  1587.  
  1588. (define_expand "epilogue"
  1589.   [(return)]
  1590.   ""
  1591.   "sh_expand_epilogue ();")
  1592.  
  1593. (define_insn "blockage"
  1594.   [(unspec_volatile [(const_int 0)] 0)]
  1595.   ""
  1596.   ""
  1597.   [(set_attr "length" "0")])
  1598.  
  1599. ;; ------------------------------------------------------------------------
  1600. ;; Scc instructions
  1601. ;; ------------------------------------------------------------------------
  1602.  
  1603. (define_insn "movt"
  1604.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  1605.     (eq:SI (reg:SI 18) (const_int 1)))]
  1606.   ""
  1607.   "movt    %0")
  1608.  
  1609. (define_expand "seq"
  1610.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1611.     (match_dup 1))]
  1612.   ""
  1613.   "operands[1] = prepare_scc_operands (EQ);")
  1614.  
  1615. (define_expand "slt"
  1616.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1617.     (match_dup 1))]
  1618.   ""
  1619.   "operands[1] = prepare_scc_operands (LT);")
  1620.  
  1621. (define_expand "sle"
  1622.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1623.     (match_dup 1))]
  1624.   ""
  1625.   "operands[1] = prepare_scc_operands (LE);")
  1626.  
  1627. (define_expand "sgt"
  1628.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1629.     (match_dup 1))]
  1630.   ""
  1631.   "operands[1] = prepare_scc_operands (GT);")
  1632.  
  1633. (define_expand "sge"
  1634.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1635.     (match_dup 1))]
  1636.   ""
  1637.   "operands[1] = prepare_scc_operands (GE);")
  1638.  
  1639. (define_expand "sgtu"
  1640.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1641.     (match_dup 1))]
  1642.   ""
  1643.   "operands[1] = prepare_scc_operands (GTU);")
  1644.  
  1645. (define_expand "sltu"
  1646.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1647.     (match_dup 1))]
  1648.   ""
  1649.   "operands[1] = prepare_scc_operands (LTU);")
  1650.  
  1651. (define_expand "sleu"
  1652.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1653.     (match_dup 1))]
  1654.   ""
  1655.   "operands[1] = prepare_scc_operands (LEU);")
  1656.  
  1657. (define_expand "sgeu"
  1658.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1659.     (match_dup 1))]
  1660.   ""
  1661.   "operands[1] = prepare_scc_operands (GEU);")
  1662.  
  1663. (define_expand "sne"
  1664.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1665.     (match_dup 1))
  1666.    (set (match_dup 0) (xor:SI (match_dup 0) (const_int 1)))]
  1667.   ""
  1668.   "operands[1] = prepare_scc_operands (EQ);")
  1669.  
  1670. ;; -------------------------------------------------------------------------
  1671. ;; Instructions to cope with inline literal tables
  1672. ;; -------------------------------------------------------------------------
  1673.  
  1674. ; 2 byte integer in line
  1675.  
  1676. (define_insn "consttable_2"
  1677.  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 2)]
  1678.  ""
  1679.  "*
  1680. {
  1681.   assemble_integer (operands[0], 2, 1);
  1682.   return \"\";
  1683. }"
  1684.  [(set_attr "length" "2")
  1685.  (set_attr "in_delay_slot" "no")])
  1686.  
  1687. ; 4 byte integer in line
  1688.  
  1689. (define_insn "consttable_4"
  1690.  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 4)]
  1691.  ""
  1692.  "*
  1693. {
  1694.   assemble_integer (operands[0], 4, 1);
  1695.   return \"\";
  1696. }"
  1697.  [(set_attr "length" "4")
  1698.   (set_attr "in_delay_slot" "no")])
  1699.  
  1700. ; 8 byte integer in line
  1701.  
  1702. (define_insn "consttable_8"
  1703.  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 6)]
  1704.  ""
  1705.  "*
  1706. {
  1707.   assemble_integer (operands[0], 8, 1);
  1708.   return \"\";
  1709. }"
  1710.  [(set_attr "length" "8")
  1711.   (set_attr "in_delay_slot" "no")])
  1712.  
  1713. ; align to a two byte boundary
  1714.  
  1715. (define_insn "align_2"
  1716.  [(unspec_volatile [(const_int 0)] 10)]
  1717.  ""
  1718.  ".align 1"
  1719.  [(set_attr "length" "0")
  1720.   (set_attr "in_delay_slot" "no")])
  1721.  
  1722. ; align to a four byte boundary
  1723.  
  1724. (define_insn "align_4"
  1725.  [(unspec_volatile [(const_int 0)] 5)]
  1726.  ""
  1727.  ".align 2"
  1728.  [(set_attr "in_delay_slot" "no")])
  1729.  
  1730. ; emitted at the end of the literal table, used to emit the
  1731. ; 32bit branch labels if needed.
  1732.  
  1733. (define_insn "consttable_end"
  1734.   [(unspec_volatile [(const_int 0)] 11)]
  1735.   ""
  1736.   "* return output_jump_label_table ();"
  1737.   [(set_attr "in_delay_slot" "no")])
  1738.  
  1739. ;; -------------------------------------------------------------------------
  1740. ;; Misc
  1741. ;; -------------------------------------------------------------------------
  1742.  
  1743. ;; String/block move insn.
  1744.  
  1745. (define_expand "movstrsi"
  1746.   [(parallel [(set (mem:BLK (match_operand:BLK 0 "" ""))
  1747.            (mem:BLK (match_operand:BLK 1 "" "")))
  1748.           (use (match_operand:SI 2 "nonmemory_operand" ""))
  1749.           (use (match_operand:SI 3 "immediate_operand" ""))
  1750.           (clobber (reg:SI 17))
  1751.           (clobber (reg:SI 4))
  1752.           (clobber (reg:SI 5))
  1753.           (clobber (reg:SI 0))])]
  1754.   ""
  1755.   "
  1756. {
  1757.   if(expand_block_move (operands))
  1758.      DONE;
  1759.   else FAIL;
  1760. }")
  1761.  
  1762. (define_insn "block_move_real"
  1763.   [(parallel [(set (mem:BLK (reg:SI 4))
  1764.            (mem:BLK (reg:SI 5)))
  1765.           (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1766.           (clobber (reg:SI 17))
  1767.           (clobber (reg:SI 0))])]
  1768.   ""
  1769.   "jsr    @%0%#"
  1770.   [(set_attr "type" "sfunc")
  1771.    (set_attr "needs_delay_slot" "yes")])
  1772.  
  1773. (define_insn "block_lump_real"
  1774.   [(parallel [(set (mem:BLK (reg:SI 4))
  1775.            (mem:BLK (reg:SI 5)))
  1776.           (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1777.           (use (reg:SI 6))
  1778.           (clobber (reg:SI 17))
  1779.           (clobber (reg:SI 4))
  1780.           (clobber (reg:SI 5))
  1781.           (clobber (reg:SI 6))
  1782.           (clobber (reg:SI 0))])]
  1783.   ""
  1784.   "jsr    @%0%#"
  1785.   [(set_attr "type" "sfunc")
  1786.    (set_attr "needs_delay_slot" "yes")])
  1787.  
  1788. ;; -------------------------------------------------------------------------
  1789. ;; Peepholes
  1790. ;; -------------------------------------------------------------------------
  1791.  
  1792. ;; This matches cases where a stack pointer increment at the start of the
  1793. ;; epilogue combines with a stack slot read loading the return value.
  1794.  
  1795. (define_peephole
  1796.   [(set (match_operand:SI 0 "arith_reg_operand" "")
  1797.     (mem:SI (match_operand:SI 1 "arith_reg_operand" "")))
  1798.    (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
  1799.   "REGNO (operands[1]) != REGNO (operands[0])"
  1800.   "mov.l    @%1+,%0")
  1801.  
  1802. ;; See the comment on the dt combiner pattern above.
  1803.  
  1804. (define_peephole
  1805.   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
  1806.     (plus:SI (match_dup 0)
  1807.          (const_int -1)))
  1808.    (set (reg:SI 18)
  1809.     (eq:SI (match_dup 0)
  1810.            (const_int 0)))]
  1811.   "TARGET_SH2"
  1812.   "dt    %0")
  1813.